package com.example.administrator.xtu_community.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.administrator.xtu_community.Adapter.MeRecyclerViewAdapter;
import com.example.administrator.xtu_community.R;
import com.example.administrator.xtu_community.simpleClass.My;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class MyFragmentCollect extends MyFragment{

    private Context context;

    private final My[] my = {new My("三叶", R.drawable.head_portrait), new My("樱花", R.drawable.test)};

    private final List<My> myList = new ArrayList<>();

    private MeRecyclerViewAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.fragment_my_collect,container,false);
        initMy();
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view_my_collect);
        GridLayoutManager layoutManager = new GridLayoutManager(context, 2);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new MeRecyclerViewAdapter(myList);
        recyclerView.setAdapter(adapter);
        return view;
    }

    private void initMy() {
        myList.clear();
        int scale = 50;
        for (int i = 0; i < scale; i++) {
            Random random = new Random();
            int index = random.nextInt(my.length);
            myList.add(my[index]);
        }
    }

}
